<?php

namespace App\Http\Logics;

use App\Model\Admin;
use App\Model\StudentClass;

class UtilLogic
{

    public static function getClassAndTeacher()
    {
        $classes = StudentClass::select('id', 'class_type', 'class_name')
            ->orderBy('class_start_time', 'desc')
            ->where('class_start_time', '<', millisecond())
            ->limit(20)
            ->get();
        $classGroup = $classes->groupBy('class_type');
        $teachers = Admin::select('id', 'role_id', 'nickname')->where('status', 0)->whereIn('role_id', [3, 4])->get();
        $teacherGroup = $teachers->groupBy('role_id');
        return [
            'class_ui' => $classGroup[1] ?? [],
            'class_h5' => $classGroup[2] ?? [],
            'teacher_ui' => $teacherGroup[3] ?? [],
            'teacher_h5' => $teacherGroup[4] ?? [],
        ];
    }
}
